package com.zhixiao.user.mapper.mock

import com.zhixiao.user.mapper.UserMapper
import com.zhixiao.user.model.User
import org.springframework.context.annotation.Primary
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Repository

val userList = mutableListOf<User>(
    User(
        "1234567890",
        "123456",
        "admin",
        "admin",
        20,
        1,
        1
    ),
    User(
        "9876543210",
        "123456",
        "user",
        "user",
        18,
        0,
        0
    ),
    User(
        "1234567891",
        "123456",
        "test",
        "test",
        25,
        1,
        0
    ),
    User(
        "1920417378001358848",
        "\$2a$10\$j28ZKKiEgOEnBZWmVDVmqOlxwkhZzh.8iyAtVYFPe2PaWGRtVk5N6",
        "ydl",
        "ydl",
        -1,
        -1,
        0
    )
)

@Repository
@Profile("dev")
@Primary
class UserMapperMock : UserMapper {
    override fun findByUsername(username: String): Int {
        return if (userList.find { it.username == username } != null) 1 else 0
    }

    override fun insert(user: User): Int {
        userList.add(user)
        print("inserted user: $user")
        return 1
    }

    override fun selectByUsername(username: String): User? {
        return userList.find { it.username == username }
    }
}
